//
//  SubAccListCell.swift
//  UserApp_iOS
//
//  Created by BestVast on 2021/5/17.
//  Copyright © 2021 linlin. All rights reserved.
//

import UIKit
let screenWidth: CGFloat = UIScreen.main.bounds.width
let screenHeight: CGFloat = UIScreen.main.bounds.height
typealias ClickCloseSure = () -> ()
class SubAccListCell: UITableViewCell {

    var backgroundImage   : UIImageView?
    
    /// 第一行的账号类别
    var styleTitle  : UILabel?
    
    /// 第一行的手机号
    var firstTitle  : UILabel?
    
    /// 第二行的手机号
    var subTitle    : UILabel?
    
    /// 第二行的名字
    var nameTitle   : UILabel?
    
    /// 删除按钮
    var delBtn      : UIButton?
    
    private var tap: ClickCloseSure?
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    /// 是否展示删除按钮
    /// - Parameters:
    ///   - delHide: 是否展示
    ///   - CompletionHandle: 点击删除按钮回调
    func showCellInfo(delHide: Bool, handle CompletionHandle: @escaping ClickCloseSure) {
        delBtn?.isHidden = delHide
        tap = CompletionHandle
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.uiConfig()
    }
    func uiConfig() {
        self.contentView.backgroundColor = UIColor.white
        backgroundImage = UIImageView.init(frame: CGRect.init(x: 10, y: 10, width: screenWidth - 20, height: 100))
        backgroundImage?.backgroundColor = colorTheme
        backgroundImage?.layer.cornerRadius = 10
        backgroundImage?.layer.masksToBounds = true
        backgroundImage?.isUserInteractionEnabled = true
        self.contentView.addSubview(backgroundImage!)
        
        styleTitle = UILabel.init(frame: CGRect.init(x: 15, y: 25, width: 70, height: 20))
        styleTitle?.font = .systemFont(ofSize: 20)
        styleTitle?.textColor = UIColor.white
        backgroundImage?.addSubview(styleTitle!)
        
        firstTitle = UILabel.init(frame: CGRect.init(x: 100, y: 25, width: 150, height: 20))
        firstTitle?.font = .systemFont(ofSize: 20)
        firstTitle?.textColor = UIColor.white
        backgroundImage?.addSubview(firstTitle!)
        
        let nameIv = UIImageView.init(frame: CGRect.init(x: 15, y: 55, width: 25, height: 25))
        nameIv.backgroundColor = .black
        backgroundImage?.addSubview(nameIv)
        nameTitle = UILabel.init(frame: CGRect.init(x: 40, y: 60, width: 60, height: 20))
        nameTitle?.font = .systemFont(ofSize: 14)
        nameTitle?.textColor = UIColor.white
        backgroundImage?.addSubview(nameTitle!)
        
        let phoneIv = UIImageView.init(frame: CGRect.init(x: 100, y: 55, width: 25, height: 25))
        phoneIv.backgroundColor = .black
        backgroundImage?.addSubview(phoneIv)
        subTitle = UILabel.init(frame: CGRect.init(x: 125, y: 60, width: 150, height: 20))
        subTitle?.font = .systemFont(ofSize: 14)
        subTitle?.textColor = UIColor.white
        backgroundImage?.addSubview(subTitle!)
        
        delBtn = UIButton.init(type: .custom)
        delBtn?.frame = CGRect.init(x: screenWidth - 20 - 20 - 20, y: 10, width: 25, height: 25)
        delBtn?.backgroundColor = .black
        backgroundImage?.addSubview(delBtn!)
        delBtn!.addTarget(self, action: #selector(clickDel), for: .touchUpInside)
        
        styleTitle?.text = "主账户"
        firstTitle?.text = "13785350000"
        nameTitle?.text = "段志强"
        subTitle?.text = "13785350000"
    }
    // 点击删除按钮
    @objc func clickDel() {
        if let clickDel = tap {
            clickDel()
        }
    }
}
